package com.mediacloud.app.newsmodule.fragment.album;

import com.mediacloud.app.assembly.banner.NetImageBannerX;
import com.mediacloud.app.assembly.util.FunKt;
import com.mediacloud.app.model.utils.DefaultBgUtil;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.adaptor.jinghua.JingHuaGridItemAdaptor;
import com.mediacloud.app.newsmodule.adaptor.jinghua.JingHuaItemViewHolder;
import com.mediacloud.app.newsmodule.fragment.BaseNewsListFragment;
import com.mediacloud.app.newsmodule.utils.NewsItemClickUtils;
import com.mediacloud.app.newsmodule.utils.TopicListDataInvoker;
import com.mediacloud.app.newsmodule.view.ResizeLoadImageBanner;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;
import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.news.BaseMessageReciver;
import com.mediacloud.app.model.news.TopicDetailDataReciver;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;

public class VodAlbumItemDetailFragment extends BaseNewsListFragment {

	protected NetImageBannerX banner;
	JingHuaItemViewHolder albumItemHolder;
	public VodAlbumItemDetailFragment()
	{
	}

	@Override
	public void initView() {
		super.initView();
		adaptor=new JingHuaGridItemAdaptor(getActivity());
		View header=LayoutInflater.from(getActivity()).inflate(R.layout.aappfactory_album_itemgridview, null);
		albumItemHolder=new JingHuaItemViewHolder(header);
		albumItemHolder.leftImgView.setBackgroundColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getMainColor());
		albumItemHolder.catalogName.setText(R.string.wanqijiemu);
		albumItemHolder.moreNews.setVisibility(View.GONE);
		albumItemHolder.jinghuaItemGridView.setOnItemClickListener(this);
		albumItemHolder.jinghuaItemGridView.setAdapter(adaptor);
		banner=new ResizeLoadImageBanner(getActivity());
		int mainColor=Color.parseColor(AppFactoryGlobalConfig.getAppServerConfigInfo(getActivity()).getColor());
		banner.currentFocusItemColor=mainColor;
//		banner.defaultBackGroundResId= DefaultBgUtil.getDefaultImageBg(getActivity());
		int bannerHeight=(int) (getResources().getDisplayMetrics().widthPixels*banner.DefaultDelta);
		banner.defaultHeight=bannerHeight;
		headerViewContainer.addView(banner,0);
		banner.dotContainer.setVisibility(View.GONE);
		banner.currentImage.setVisibility(View.GONE);
		//		banner.textDesc
		//		banner.bottomLabelLayout
		mCatalogContentItemListView.setAdapter(null);
		headerViewContainer.addView(header);
		//		adaptor=new JingHuaGridItemAdaptor(getActivity());
		//		embedGridView.setAdapter(adaptor);


		//		banner.addItem(item.getLogo(), item.getTitle(),AppFactoryGlobalConfig.getDefaultImageLoadDrawable());
		//	banner.updateLayout();
		matchLBSCataglogId();
	}
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
							long id) {
		int index = position;
		if(index<0)
			return;
		ArticleItem item = (ArticleItem) adaptor.getItem(index);
		catalogItem.setCatid("");
		NewsItemClickUtils.OpenItemNewsHandle(getActivity(), item.getType(),item,catalogItem);
	}
	@Override
	protected void initDataInvoker()
	{
		dataInvoker=new TopicListDataInvoker(dataCallback);
	}
	@Override
	protected void getNewsListData()
	{
		((TopicListDataInvoker)dataInvoker).getTopicDetailById(catalogID, pageNum,pageSize);
	}
	protected Class<? extends BaseDataInvokeCallBack<? extends BaseMessageReciver>> getDataInvokeCallBackClass()
	{
		return AlbumItemDataInvokeCallBack.class;
	}

	public class AlbumItemDataInvokeCallBack extends BaseDataInvokeCallBack<TopicDetailDataReciver>
	{
		@Override
		public void success(TopicDetailDataReciver result)
		{
			if(adaptor==null)
				return;
			isLoading=false;
//			mCatalogContentItemListView.setPullLoadEnable(result.more);
			String name=result.name;
			if(pageNum==1)
			{
				mXSmartRefreshLayout.finishRefresh();
				banner.cleanAll();
				banner.addItem(result.logo, name,AppFactoryGlobalConfig.getDefaultImageLoadDrawable());
				banner.updateLayout();
				if(adaptor.getListContentData() != null)
					adaptor.getListContentData().clear();
			}
			if(result.more)
				mXSmartRefreshLayout.finishLoadMore();
			else
				mXSmartRefreshLayout.finishLoadMoreWithNoMoreData();
			if (adaptor.getListContentData() == null)
				adaptor.setListContentData(result.articleList);
			else
				adaptor.getListContentData().addAll(
						result.articleList);
			adaptor.notifyDataSetChanged();
		/*	mCatalogContentItemListView.stopLoadMore();
			mCatalogContentItemListView.stopRefresh();*/
			if (!result.state)
			{
                showStateView(TYPE_NO_CONTENT, false);
				banner.setVisibility(View.INVISIBLE);
			} else
			{
                closeStateView();
				banner.setVisibility(View.VISIBLE);
			}


		}
	}
}